<?php

defined('BASEPATH') or die('forbidden');

class Totalpayment_Controller Extends Controller {

	private $rolename;
	private $inc;

	function _init() {//print_r($_SESSION['tttttkk']);
		check_level(50, segment(0), segment(1));

		$this->inc = $this->config['inc'];
	}

	function index() {
		$area_host = !empty($_SESSION['area_selected_id']) ? $_SESSION['area_selected_id'] : '';
		if ($area_host == '')
		{
			echo "<script>alert('" . translate('C_SELECT_AREA_TEXT') . "');</script>";
		}
		$this->view->display("dbvip/totalpayment/index");
	}

	function flexigrid() {
			
		list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();
			
		$areanum = $_SESSION['area_selected_id'];
		//echo " areanum:$areanum ";

		//万不得已了，总不能传一个空数据让数据库报销了。。
		if($areanum == '')
		{
			$areanum = 1;
		}

		//先从数据库中得到要连数据的用户名与密码
		$sql="select * from platform_game_mapping where area_num = $areanum ";
			
		//echo " sql = ".$sql." " ;
		if(null == ($row = $this->db->one($sql)))
		{
			//echo " can not find area message ";
			return;
		}
			
		//新创建一个连接
		$t_db_arr = array
		(
		        'library' => 'database',
		        'type' => 'mysql',
		        'host' => $row['databaseip'],
		        'name' => $row['dbname'],
		        'user' => $row['username'],
		        'password' => $row['password'],
		        'pconnect' => false,
		        'debug' => true,
		        'prefix' => 'tt_',
		);
		$t_db = new Database($t_db_arr);
		//$this->db->connect('111.75.194.177','root','654321');
		//200090016 表示 充值	
		$sql = "SELECT COUNT(*) AS num FROM $row[dbname].player_oper_log_data as A, $row[dbname].player as B where {$where} 
				and oper_id = 200090016 and A.role_id = B.id";
		//echo " sql2:$sql ";
		$one = $t_db->one($sql);
		$total = $one['num'];
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";
			
		$sql = "SELECT {$colsinfo} FROM $row[dbname].player_oper_log_data as A, $row[dbname].player as B where {$where} 
				and oper_id = 200090016 and A.role_id = B.id {$orderby} LIMIT {$offset},{$rp}";
		$t_db->query($sql);
		//echo "sql:$sql ";
		//$id = 0;
		while ($n = $t_db->get_array('default'))
		{
			//print_r($n);
			//时间需要由数字转成字符串
			$n['oper_lasttime']=get_datetime($n['oper_lasttime']);
			$rows[] = array('id' => $n['id'], 'cell' => $n);
			//$id = $id+1;
		}
		//var_dump($rows);
		$result = array(
	            'page' => $page,
	            'total' => $total,
	            'rows' => $rows
		);
			
		$t_db->free_all();
		echo json_encode($result);
	}

}

?>